<?php

class My_HTML_Page {

    private $Title;
    private $BodyContent;
    private $StyleSheet;
    private $Script;

    function __construct() {
        $this->StyleSheet = array();
        $this->Script = array();
        $this->BodyContent = "\n\n\n";
    }

    public function addBodyContent($str) {
        $this->BodyContent .= $str . "\n";
    }

    public function addStyleSheet($path) {
        array_push($this->StyleSheet, $path);
    }

    public function addScript($path) {
        array_push($this->Script, $path);
    }

    public function setTitle($Title) {
        $this->Title = $Title;
    }

    public function display() {
        echo '<!DOCTYPE html>' . "\n" . '<html>' . "\n\t" . '<head>' . "\n\t\t" . '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n\t\t";
        if (isset($this->StyleSheet)) {
            foreach ($this->StyleSheet as $style) {
                echo '<link rel="stylesheet" type="text/css" href="' . $style . '" />' . "\n\t\t";
            }
        }
        if (isset($this->Script)) {
            foreach ($this->Script as $script) {
                echo '<script type="text/javascript" src="' . $script . '"></script>' . "\n\t\t";
            }
        }
        if (isset($this->Title)) {
            echo '<title>' . $this->Title . '</title>' . "\n\t";
            echo '</head>' . "\n\t" . '<body>' . $this->BodyContent . "\n\t";
            echo '</body>' . "\n" . '</html>';
        }
    }
    
      public function toString() {
          $str="";
        $str .= '<!DOCTYPE html>' . "\n" . '<html>' . "\n\t" . '<head>' . "\n\t\t" . '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n\t\t";
        if (isset($this->StyleSheet)) {
            foreach ($this->StyleSheet as $style) {
                $str .= '<link rel="stylesheet" type="text/css" href="' . $style . '" />' . "\n\t\t";
            }
        }
        if (isset($this->Script)) {
            foreach ($this->Script as $script) {
                $str .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n\t\t";
            }
        }
        if (isset($this->Title)) {
            $str .= '<title>' . $this->Title . '</title>' . "\n\t";
            $str .= '</head>' . "\n\t" . '<body>' . $this->BodyContent . "\n\t";
            $str .= '</body>' . "\n" . '</html>';
        }
        return $str;
    }

}
